﻿@page "/DynamicTab"

<h3>DynamicTab</h3>


<RadzenTabs @ref="tabs" RenderMode="TabRenderMode.Client" @bind-SelectedIndex=@selectedIndex>
    <Tabs>
        @foreach (var item in items)
        {
            <RadzenTabsItem   Text="@($"Tab {items.IndexOf(item).ToString()}")">

                <RadzenCard>
                     <RadzenRow>
                          <RadzenColumn Size="1">
                            Image Width/Height:
                          </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.ScanAreaWidth.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                            <RadzenTextBox Value="@item.ScanAreaHeight.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                     </RadzenRow>

                     <RadzenRow>
                        <RadzenColumn Size="1">
                            Rotation Angle:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.ScanRotation.ToString()" aria-label="Default TextBox" />
                        </RadzenColumn>
                     </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            Scan Time:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.ScanTime.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                    </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            Line:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.ScanLine.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                    </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            Point:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.ScanPoint.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                    </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            Lithography Operating Mode:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <select width="100px" @bind="@item.PatternAfmOperateModeType">
                                @foreach (var value in Enum.GetValues(typeof(AfmOperateModeTypeEnum)))
                                {
                                    <option value="@value">@value.ToString()</option>
                                }
                            </select>
                        </RadzenColumn>
                    </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            Set Point:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.ScanSetPoint.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                    </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            P gain:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.PGain.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                    </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            I gain:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.IGain.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                    </RadzenRow>

                    <RadzenRow>
                        <RadzenColumn Size="1">
                            Vibrating ampl:
                        </RadzenColumn>
                        <RadzenColumn Size="9">
                            <RadzenTextBox Value="@item.VibratingAmpl.ToString()" Style="width: 100%" aria-label="Default TextBox" />
                        </RadzenColumn>
                    </RadzenRow>
                </RadzenCard>

            </RadzenTabsItem>
        }
    </Tabs>
</RadzenTabs>

<RadzenStack Orientation="Radzen.Orientation.Horizontal" JustifyContent="JustifyContent.Center" Gap="0.5rem" class="rz-pt-4 rz-pb-8">
    <RadzenButton Click="AddItem">Add Item</RadzenButton>
    <RadzenButton Click="RemoveItem">Remove Item</RadzenButton>
</RadzenStack>

@code {

    RadzenTabs tabs;
    int selectedIndex = 0;

    List<MeasurementModel> items = new List<MeasurementModel>();
    int i = 0;

    protected override Task OnInitializedAsync()
    {
        items.Add(new MeasurementModel
            {
                IGain = 1000,
                PatternAfmOperateModeType = AfmOperateModeTypeEnum.StaticForce,
                PGain = 5000,
                ScanAreaHeight = 50,
                ScanAreaWidth = 30,
                ScanLine = 512,
                ScanPoint = 125,
                ScanRotation = 90,
                ScanSetPoint = 12,
                ScanTime = 5,
                VibratingAmpl = 0,
            });
        return base.OnInitializedAsync();
    }

    void AddItem()
    {
        items.Add(new MeasurementModel
        {

        });
        tabs.Reload();
    }

    void RemoveItem()
    {
        items.RemoveAt(selectedIndex);
        if (selectedIndex >= items.Count) selectedIndex = items.Count - 1;
        tabs.Reload();
    }


    public class MeasurementModel
    {
        public double ScanAreaWidth { get; set; }

        public double VibratingAmpl { get; set; }

        public double IGain { get; set; }

        public double ScanSetPoint { get; set; }

        public AfmOperateModeTypeEnum PatternAfmOperateModeType { get; set; }

        public double ScanPoint { get; set; }

        public double ScanLine { get; set; }

        public double ScanTime { get; set; }

        public double ScanRotation { get; set; }

        public double ScanAreaHeight { get; set; }

        public double PGain { get; set; }
    }

    public enum AfmOperateModeTypeEnum
    {
        [Description("静态力")]
        StaticForce = 2,

        [Description("动态力")]
        DynamicForce = 3
    }
}
